package com.ja.openchat.ui.me;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.databinding.FragmentWalletBinding;
import com.ja.openchat.viewmodels.WalletViewModel;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.interfaces.OnCancelListener;
import com.lxj.xpopup.interfaces.OnConfirmListener;

import me.goldze.mvvmhabit.base.BaseFragment;

//钱包界面
public class WalletFragment extends BaseFragment<FragmentWalletBinding, WalletViewModel> {
    boolean hasShow;

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_wallet;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.mUC.getShowPaymentPasswordDialogEvent().observe(this, aBoolean -> {
            tipSetWalletPaymentPasswordDialog(aBoolean);
        });
    }

    @Override
    public void initData() {
        super.initData();
    }

    @Override
    public void onResume() {
        super.onResume();
        viewModel.requestData();
    }

    //设置支付密码
    private void tipSetWalletPaymentPasswordDialog(boolean hasPaymentPassword) {
        if (hasShow)
            return;
        hasShow = true;
        new XPopup.Builder(getActivity()).autoDismiss(true).asConfirm(getString(R.string.dialog_title_tip)
                , getString(R.string.not_set_pay_pw_to_set), getString(R.string.cancle_text),getString(R.string.set_up_text)
                , new OnConfirmListener() {
            @Override
            public void onConfirm() {
                if (hasPaymentPassword) {
                    startContainerActivity(SetPayPwdOldFragment.class.getCanonicalName());
                } else {
                    startContainerActivity(SetPayPwdFragment.class.getCanonicalName());
                }
            }
        }, new OnCancelListener() {
            @Override
            public void onCancel() {

            }
        }, false).show();
    }
}